package com.ext.aic.utils;

import android.text.TextUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class TimeUtils {
    public static long toTimestampByHM(String time) {
        if (TextUtils.isEmpty(time)) {
            return 0;
        }
        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
        LocalTime localTime = LocalTime.parse(time, timeFormatter);
        LocalDateTime dateTime = LocalDateTime.of(LocalDate.now(), localTime);
        return dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

    public static long toTimestampByHM(int hour, int minute) {
        String builder = (hour >= 10 ? hour : "0" + hour) +
                ":" +
                (minute >= 10 ? minute : "0" + minute);
        return toTimestampByHM(builder);
    }
}
